package com.ruoyi.system.api.factory;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.RemoteSjsjService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

/**
 * 数据世界服务降级处理
 *
 * @author jingma
 */
@Component
public class RemoteSjsjFallbackFactory implements FallbackFactory<RemoteSjsjService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteSjsjFallbackFactory.class);

    @Override
    public RemoteSjsjService create(Throwable throwable)
    {
        log.error("数据世界服务调用失败", throwable);
        return new RemoteSjsjService()
        {
            @Override
            public R<JSONObject> index(JSONObject myParams) {
                return R.fail("数据世界接口请求失败:" + throwable.getMessage());
            }

            @Override
            public R<JSONObject> upload(JSONObject myParams, MultipartFile[] files) {
                return R.fail("上传文件失败:" + throwable.getMessage());
            }
        };
    }
}
